package com.iman.sumer.service.impl.teamgroup;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.springframework.stereotype.Service;

import com.iman.common.hibernate.TemplateQLService;
import com.iman.common.support.Page;
import com.iman.sumer.service.teamgroup.GroupMemberService;
import com.iman.sumer.vo.teamgroup.GroupMemberVo;

@Service
public class GroupMemberServiceImpl implements GroupMemberService {
	@Inject
    private TemplateQLService templateQLService;

	@Override
	public GroupMemberVo getGroupMemberByID(long memberId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void addGroupMember(Map params) {
		templateQLService.executeSQLUpdate("add_group_member", params);
	}


	@Override
	public Page<GroupMemberVo> getMemberList(Map<String, Object> params) {
		Integer ps = Integer.valueOf(params.get("ps").toString());
		Integer pn = Integer.valueOf(params.get("pn").toString());
		params.put("startNo", ps*pn);
 		Page<GroupMemberVo> vos = templateQLService.findByPagedSQLBeanQuery(
				"group_member_list", params, Page.getStartOfPage(pn, ps), ps,
				GroupMemberVo.class);
		return vos;
	}


	@Override
	public List<GroupMemberVo> getGroupMemberList(Map<String, Object> params) {
		List<GroupMemberVo> vos = templateQLService.findBySQLMapQuery("group_member_list", params);
		return vos;
	}

	@Override
	public Map getGroupCreater(Map params) {
		List<HashMap<String, Object>> vos = templateQLService.findBySQLMapQuery("group_creater", params);
		if(vos.size()>0){
			
			return vos.get(0);
		}else{
			return null;
		}
	}

	@Override
	public Map getMemberById(Map<String, Object> params) {
		List<Map> vos = templateQLService.findBySQLMapQuery("member_by_id", params);
		if(vos!=null && !vos.isEmpty()){
			return vos.get(0);
		}
		return null;
	}

	@Override
	public void updateGroupMember(Map params) {
		templateQLService.executeSQLUpdate("update_group_member", params);
	}

	@Override
	public Map getMemberUserInfo(Map params) {
		List<HashMap<String, Object>> vos = templateQLService.findBySQLMapQuery("member_uerinfo", params);
		if(vos.size()>0){
			return vos.get(0);
		}else{
			return null;
		}
	}

	@Override
	public Map getGroupMemberById(Map<String, Object> params) {
		List<HashMap<String, Object>> vos = templateQLService.findBySQLMapQuery("group_member_uerinfo", params);
		if(vos.size()>0){
			return vos.get(0);
		}else{
			return null;
		}
	}

	@Override
	public int isGroupMember(Map params) {
		List<GroupMemberVo> list = templateQLService.findBySQLBeanQuery("group_member_list", params,GroupMemberVo.class);
		if(list == null || list.size() == 0){
			return 0;
		}
		return 1;
	}



	
	

}
